# Reverse Models
m.comp.1 <- lm(rel_feel ~ rel_banperm + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.1)
y.comp.1 <- lm(liberal ~ rel_banperm*rel_feel + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.1)

m.comp.2 <- lm(rel_feel ~ rel_banperm + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.2)
y.comp.2 <- lm(liberal ~ rel_banperm*rel_feel + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.2)

m.comp.3 <- lm(rel_feel ~ rel_banperm + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.3)
y.comp.3 <- lm(liberal ~ rel_banperm*rel_feel + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.3)

m.comp.4 <- lm(rel_feel ~ rel_banperm + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.4)
y.comp.4 <- lm(liberal ~ rel_banperm*rel_feel + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.4)

m.comp.5 <- lm(rel_feel ~ rel_banperm + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.5)
y.comp.5 <- lm(liberal ~ rel_banperm*rel_feel + fem + I(age/10) + edu_high + religiosity + leftright + rel_muslim + rel_dev + rel_rad + rel_immigrant, data=imp.data.5)

ACME.1 <- ACME.fun(m.comp.1, y.comp.1)
ACME.2 <- ACME.fun(m.comp.2, y.comp.2)
ACME.3 <- ACME.fun(m.comp.3, y.comp.3)
ACME.4 <- ACME.fun(m.comp.4, y.comp.4)
ACME.5 <- ACME.fun(m.comp.5, y.comp.5)

c.1 <- apply(ACME.1, 2, mean)
c.2 <- apply(ACME.2, 2, mean)
c.3 <- apply(ACME.3, 2, mean)
c.4 <- apply(ACME.4, 2, mean)
c.5 <- apply(ACME.5, 2, mean)

s.1 <- apply(ACME.1, 2, sd)
s.2 <- apply(ACME.2, 2, sd)
s.3 <- apply(ACME.3, 2, sd)
s.4 <- apply(ACME.4, 2, sd)
s.5 <- apply(ACME.5, 2, sd)

coefs <- cbind(c.1, c.2, c.3, c.4, c.5)
c.combined <- apply(coefs, 1, mean)

var.within <- cbind(s.1^2, s.2^2, s.3^2, s.4^2, s.5^2)
var.within <- apply(var.within, 1, mean)

m <- 5
var.between <- (coefs - c.combined)^2
var.between <-  apply(var.between, 1, sum)
var.between <-  (m-1)^-1 * var.between

s.combined <- sqrt(var.within + (1 + m^-1) * var.between )

combined.res <- cbind(c.combined, s.combined)
combined.res <- round(combined.res, 3)

av.ACME.rev <- combined.res[3,1]
av.ACME.se.rev <- combined.res[3,2]

ANDE.1 <- ANDE.fun(m.comp.1, y.comp.1)
ANDE.2 <- ANDE.fun(m.comp.2, y.comp.2)
ANDE.3 <- ANDE.fun(m.comp.3, y.comp.3)
ANDE.4 <- ANDE.fun(m.comp.4, y.comp.4)
ANDE.5 <- ANDE.fun(m.comp.5, y.comp.5)

c.1 <- apply(ANDE.1, 2, mean)
c.2 <- apply(ANDE.2, 2, mean)
c.3 <- apply(ANDE.3, 2, mean)
c.4 <- apply(ANDE.4, 2, mean)
c.5 <- apply(ANDE.5, 2, mean)

s.1 <- apply(ANDE.1, 2, sd)
s.2 <- apply(ANDE.2, 2, sd)
s.3 <- apply(ANDE.3, 2, sd)
s.4 <- apply(ANDE.4, 2, sd)
s.5 <- apply(ANDE.5, 2, sd)

coefs <- cbind(c.1, c.2, c.3, c.4, c.5)
c.combined <- apply(coefs, 1, mean)

var.within <- cbind(s.1^2, s.2^2, s.3^2, s.4^2, s.5^2)
var.within <- apply(var.within, 1, mean)

m <- 5
var.between <- (coefs - c.combined)^2
var.between <-  apply(var.between, 1, sum)
var.between <-  (m-1)^-1 * var.between

s.combined <- sqrt(var.within + (1 + m^-1) * var.between )

combined.res <- cbind(c.combined, s.combined)
combined.res <- round(combined.res, 3)

av.ANDE.rev <- combined.res[3,1]
av.ANDE.se.rev <- combined.res[3,2]
